<xform xmlns:h="http://www.w3.org/1999/xhtml"
       xmlns="http://www.w3.org/2002/xforms"
       xmlns:ev="http://www.w3.org/2001/xml-events"
       xmlns:xsd="http://www.w3.org/2001/XMLSchema"
       xmlns:jr="http://openrosa.org/javarosa">

<h:title>Batch Patient Registration</h:title>
<meta jr:name="jr-patient-batch-reg"/>

<model>
    
<instance>
	<patients xmlns="">
	    <patient jr:template="">
	        <id />
	        <name>
	            <family />
	            <given />
	            <middle />
	        </name>
	        <sex />
	        <dob />
	        <treatment-start />
	        <weight-history>
	            <reading jr:template="">
	                <weight />
	                <taken-on />
	            </reading>
	        </weight-history>
	    </patient>
	</patients>
</instance>

<bind nodeset="patients/patient/name/family" required="true()" />		
<bind nodeset="patients/patient/name/given" required="true()" />	
<bind nodeset="patients/patient/sex" required="true()" />	
<bind nodeset="patients/patient/dob" type="xsd:date" required="true()" />
<bind nodeset="patients/patient/treatment-start" type="xsd:date" />
<bind nodeset="patients/patient/weight-history/reading/weight" type="xsd:int" required="true()" />
<bind nodeset="patients/patient/weight-history/reading/taken-on" type="xsd:date" required="true()" />

<itext>
  <translation lang="English">
    <text id="patient">
      <value>Patient</value>
    </text>
    <text id="id">
      <value form="long">Patient ID</value>
      <value form="short">ID</value>
    </text>
    <text id="family-name">
      <value>Family Name</value>
    </text>
    <text id="given-name">
      <value>Given Name</value>
    </text>
    <text id="middle-name">
      <value>Middle Name</value>
    </text>
    <text id="sex">
      <value>Sex</value>
    </text>
    <text id="sex-male">
      <value>Male</value>
    </text>
    <text id="sex-female">
      <value>Female</value>
    </text>
    <text id="sex-unknown">
      <value>Unknown</value>
    </text>
    <text id="dob">
      <value form="long">Date of Birth</value>
      <value form="short">DOB</value>
    </text>
    <text id="treatment-start">
      <value form="long">Treatment Started on...</value>
      <value form="short">Treatment Began</value>
    </text>
    <text id="weight-reading">
      <value>Weight Reading</value>
    </text>
    <text id="weight">
      <value>Weight</value>
    </text>
    <text id="weight-date">
      <value form="long">Date Taken</value>
      <value form="short">Taken</value>
    </text>
  </translation>
</itext>

</model>

<group>
  <label ref="jr:itext('patient')" />
  <repeat nodeset="patient" jr:initCount="1">
  
    <input ref="id"><label ref="jr:itext('id')" /></input>
    <input ref="name/family"><label ref="jr:itext('family-name')" /></input>
    <input ref="name/given"><label ref="jr:itext('given-name')" /></input>
    <input ref="name/middle"><label ref="jr:itext('middle-name')" /></input>
    <select1 ref="sex">
      <label ref="jr:itext('sex')" />
      <item><label ref="jr:itext('sex-male')" /><value>m</value></item>
      <item><label ref="jr:itext('sex-female')" /><value>f</value></item>
      <item><label ref="jr:itext('sex-unknown')" /><value>u</value></item>
    </select1>
    <input ref="dob"><label ref="jr:itext('dob')" /></input>
    <input ref="treatment-start"><label ref="jr:itext('treatment-start')" /></input>
  
    <group>
      <label ref="jr:itext('weight-reading')" />
      <repeat nodeset="weight-history/reading">
        
        <input ref="weight"><label ref="jr:itext('weight')" /></input>
        <input ref="taken-on"><label ref="jr:itext('weight-date')" /></input>
        
      </repeat>
    </group>
  
  </repeat>
</group>

</xform>